<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<link rel="stylesheet" type="text/css" href="../css/common.css"/>
<link rel="stylesheet" type="text/css" href="../font/iconfont.css"/>
<style>
#dongtaibox{
	padding:5px;
	background: #fff;
	box-shadow:0 0 1px #ccc;
	-webkit-box-shadow:1px 0 1px #ccc;
	padding-bottom: 0;
}
#contetns{
	display: block;
	width:100%;
	border: 0;
	height: 18rem;
	overflow:auto;
}
#contetns:focus{
	outline: none;
}
#photos{
	flex-wrap:wrap;
	-webkit-flex-wrap: wrap;
}
.photoitem{
	display: block;
	width: 23.5%;
	background: #eee;
	margin-bottom: 4px;
	overflow: hidden;
	margin-right: 4px;
}
#addimg{
	text-align: center;
	font-size:2rem;
	color: #ccc;
	line-height: 5rem;
}
.yyshuru{
	display: block;
	text-align: center;
	height:3rem;
	line-height: 3rem;
	color: orangered;
	font-size: 14px;
}
</style>
</head>
<body>
<div id="jcontent" class="jcontent">
	<div id="dongtaibox">
		<textarea id="contetns" placeholder="这一刻的想法..."></textarea>
		<div id="photos" class="jflex">
		</div>
	</div>
	<a id="yyshuru" class="yyshuru"><i class="iconfont icon-yuyin"></i>&nbsp;&nbsp;试试语音输入</a>
</div>
<script src="../js/mui.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../js/common.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
var screenW;
mui.plusReady(function(){
	window.setTimeout(function(){
		datainit();
	},360);
});

function datainit(){
	screenW=webapp.getScreenW()/4-10;
	contentId=webapp.GetQueryString("id");
	//加载帖子内容
	if(webapp.GetQueryString("type")=="2"){
		webapp.ajax({
			url:"/carLife/admin/interface/post/selectDetailMessageById?id="+contentId,
			success:function(json){
				var newContent="@"+json.data.nickName+"\n"+json.data.content;
				document.getElementById("contetns").value=newContent;
				doImg(json.data.imagesList);
			}
		});
		return false;
	}
	
	//加载动态内容
	webapp.ajax({
		url:"/carLife/common/interface/dynamic/selectDynamicDetail?id="+contentId,
		success:function(json){
			var newContent="@"+json.data.sellerName+"\n"+json.data.content;
			document.getElementById("contetns").value=newContent;
			//处理图片
			doImg(json.data.imagesList);
		}
	});
	
}

//
function doImg(imgs){
	for(var i=0;i<imgs.length;i++){
		var _img=imgs[i];
		var newNode = document.createElement("div"); 
		newNode.className="photoitem pitem";
		var newImg=webapp.config.restUrl+_img.path+"-120"+_img.type;
		newNode.innerHTML ='<img style="height:'+screenW+'px;line-height:'+screenW+'px ;" data-imgpath="'+newImg+'" class="img upload-img" src="'+newImg+'"/>';
		document.getElementById("photos").insertBefore(newNode,document.getElementById("addimg")); // 这两种方
	}
}

//帖子保存
window.addEventListener("riconClick", function(e) {
	//隐藏输入法
	webapp.hideTypewriting(["contetns"]);
	webapp.showWaiting();
	webapp.ajax({
		url:"/carLife/admin/interface/detailMessage/forward?targetId="+webapp.GetQueryString("id"),
		data:{
			content:document.getElementById("contetns").value,
			type:webapp.GetQueryString("type")
		},
		success:function(json){
			var _webview=plus.webview.getWebviewById("list.html");
			mui.fire(_webview,"forwordNumUpdate",{code:json.code,id:webapp.GetQueryString("id")});
			mui.fire(_webview,"pullDown");
		}
	});
});
</script>
</body>
</html>
